package org.afun.oldhand.forum.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.afun.oldhand.R;
import org.afun.oldhand.forum.javaBean.ItemClassiferBean;

import java.util.List;

public class ForumBottomClassiferItemAdapter extends RecyclerView.Adapter<ForumBottomClassiferItemAdapter.ForumBottomClassiferItemViewHolder> {
    private List<ItemClassiferBean> data;
    private Context context;
    private ForumBottomClassiferItemAdapter.OnOrderRecyclerItemClickListener onItemRecyclerItemClickListener;

    public ForumBottomClassiferItemAdapter(List<ItemClassiferBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @NonNull
    @Override
    public ForumBottomClassiferItemAdapter.ForumBottomClassiferItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.forum_listitem5, null);
        return new ForumBottomClassiferItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ForumBottomClassiferItemViewHolder holder, int position) {
//        System.out.println(data.get(position).getText());
        holder.text.setText(data.get(position).getText());
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public class ForumBottomClassiferItemViewHolder extends RecyclerView.ViewHolder {
        private TextView text;
        public ForumBottomClassiferItemViewHolder(@NonNull View itemView) {
            super(itemView);
            text=itemView.findViewById(R.id.tv);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemRecyclerItemClickListener!=null){
                        onItemRecyclerItemClickListener.onItemRecyclerItemClick(getAdapterPosition());
                    }
                }
            });

        }
    }

    public void setOrderItemClickListener(ForumBottomClassiferItemAdapter.OnOrderRecyclerItemClickListener listener){
        onItemRecyclerItemClickListener=listener;
    }

    public interface OnOrderRecyclerItemClickListener{
        void onItemRecyclerItemClick(int position);
    }
}
